#ifndef ARPLISTENER_H
#define ARPLISTENER_H
#include <functional>
#include <QObject>
#include <QThread>
#include <pcap.h>
#include <common.h>

using ArpPktCallback = std::function<void(std::shared_ptr<arp_packet>)>;

class ArpListener : public QThread
{
    Q_OBJECT
public:
    explicit ArpListener(pcap_t *handle, const QString& dev_name,ArpPktCallback cb, QObject *parent = nullptr);
    ~ArpListener();

protected:
    void run() override;

    bool event(QEvent* ) override;
signals:

private:
    void listen_arp_pkt();
    void stop_listen();

    static void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);

private:
    QString dev_name_;
    ArpPktCallback cb_;
    pcap_t *handle_{nullptr};
};

#endif // ARPLISTENER_H
